<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>科室医生列表</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <script src="/js/jquery.min.js"></script>
</head>
<body>
<div class="container mt-5">
    <h2 class="text-center mb-4">科室医生列表</h2>
    <ul id="doctorList" class="list-group"></ul>
</div>

<script>
    $(document).ready(function () {
        const urlParams = new URLSearchParams(window.location.search);
        const departmentId = urlParams.get('departmentId');

        if (!departmentId) {
            alert("科室ID不能为空");
            return;
        }

        $.get('/users/getDoctorsByDepartmentId/' + departmentId, function (data) {
            $('#doctorList').empty();
            if (data && data.length > 0) {
                $.each(data, function (index, doctor) {
                    $('#doctorList').append(
                        '<li class="list-group-item">' +
                        '<div class="d-flex justify-content-between align-items-center">' +
                        '<div>' +
                        '<h5>' + doctor.name + '</h5>' +
                        '<p>职称: ' + (doctor.title || '暂无信息') + '</p>' +
                        '<p>简介: ' + (doctor.description || '暂无简介') + '</p>' +
                        '</div>' +
                        '<a href="/schedule?doctorId=' + doctor.id + '" class="btn btn-primary ms-3">预约</a>' +
                        '</div>' +
                        '</li>'
                    );
                });
            } else {
                $('#doctorList').append('<li class="list-group-item text-muted">暂无医生信息</li>');
            }
        }).fail(function (jqXHR, textStatus, errorThrown) {
            console.error('获取医生数据失败:', textStatus, errorThrown);
            alert('获取医生数据失败: ' + jqXHR.responseText);
        });
    });
</script>

</body>
</html>
